package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Where;
import org.springframework.context.annotation.Lazy;
import com.mes.common.domain.BasicModel;


/**
 * @author lcs
 *
 */
@Entity()
@Table(name = "T_LINKS")
@Where(clause = "dependtype = '1'")
@BatchSize(size=20)
@Lazy(value=true)
public class PartTaskLink extends BasicModel {
	
	public final static int LINKTYPE_FTS = 1;
	public final static int LINKTYPE_FTF = 2;
	public final static int LINKTYPE_STS = 3;
	public final static int LINKTYPE_STF = 4;
	
	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name="UNIQUE_ID")
	protected String uniqueId; 
	
	@Column(name="SUCCUID")
	protected String succPartTaskUid;

	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SUCCUID", insertable = false, updatable = false)
	protected PartTask succPartTask;

	@Column(name="PREDUID")
	protected String predPartTaskUid;

	// many-to-one
		@ForeignKey(name = "null")
		@ManyToOne(fetch = FetchType.LAZY)
		@JoinColumn(name = "PREDUID", insertable = false, updatable = false)
	protected PartTask predPartTask;

	@Column(name="LINKQTY",precision=25,scale=6)
	protected Double linkQty;
	
	@Column(name="LINKLAG",precision=10,scale=0)
	protected Long linkLag;
	
	@Column(name="LINKTYPE",precision=10,scale=0)
	protected Long linkType;


	@Column(name="DEPENDTYPE",length=10)
	protected String dependType="0";
	
	/*不使用了
	protected TypesData dependTypeDesc;
*/
	@Column(name="LOCKLEVEL")
	protected Long lockLevel;

	@Column(name="LOCKEXPIREDATE",length=7)
	protected Date lockExpireDate;
	
	@Formula("(select types.iddesc from b_typesdata types where types.typesname = 'linktype' and types.id = LINKTYPE)")
	protected String linkTypeIddesc;

	@Column(name="ISINEFFECT",precision=2,scale=0)
	private Boolean effective;

	public Boolean getEffective() {
		return effective;
	}

	public void setEffective(Boolean effective) {
		this.effective = effective;
	}

	public String getsuccPartTaskUid() {
		return succPartTaskUid;
	}

	public void setsuccPartTaskUid(String succPartTaskUid) {
		this.succPartTaskUid = succPartTaskUid;
	}

	public PartTask getsuccPartTask() {
		return succPartTask;
	}

	public void setDependType(String dependType) {
		this.dependType = dependType;
	}

	public void setsuccPartTask(PartTask succPartTask) {
		this.succPartTask = succPartTask;
		this.succPartTaskUid=(succPartTask!=null)?succPartTask.getUuid():null;
	}

	public String getpredPartTaskUid() {
		return predPartTaskUid;
	}

	public void setpredPartTaskUid(String predPartTaskUid) {
		this.predPartTaskUid = predPartTaskUid;
	}

	public PartTask getpredPartTask() {
		return predPartTask;
	}

	public void setpredPartTask(PartTask predPartTask) {
		this.predPartTask = predPartTask;
		this.predPartTaskUid=(predPartTask!=null)?predPartTask.getUuid():null;

	}

	public Double getLinkQty() {
		return linkQty;
	}

	public void setLinkQty(Double linkQty) {
		this.linkQty = linkQty;
	}


	public Long getLinkType() {
		return linkType;
	}

	public void setLinkType(Long linkType) {
		this.linkType = linkType;
	}

	public String getDependType() {
		return dependType;
	}

	public Long getLockLevel() {
		return lockLevel;
	}

	public void setLockLevel(Long lockLevel) {
		this.lockLevel = lockLevel;
	}

	public Date getLockExpireDate() {
		return lockExpireDate;
	}

	public void setLockExpireDate(Date lockExpireDate) {
		this.lockExpireDate = lockExpireDate;
	}

	public Long getLinkLag() {
		return linkLag;
	}

	public void setLinkLag(Long linkLag) {
		this.linkLag = linkLag;
	}

	public String getLinkTypeIddesc() {
		return linkTypeIddesc;
	}

	public void setLinkTypeIddesc(String linkTypeIddesc) {
		this.linkTypeIddesc = linkTypeIddesc;
	}

	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	public String getSuccPartTaskUid() {
		return succPartTaskUid;
	}

	public void setSuccPartTaskUid(String succPartTaskUid) {
		this.succPartTaskUid = succPartTaskUid;
	}

	public PartTask getSuccPartTask() {
		return succPartTask;
	}

	public void setSuccPartTask(PartTask succPartTask) {
		this.succPartTask = succPartTask;
	}

	public String getPredPartTaskUid() {
		return predPartTaskUid;
	}

	public void setPredPartTaskUid(String predPartTaskUid) {
		this.predPartTaskUid = predPartTaskUid;
	}

	public PartTask getPredPartTask() {
		return predPartTask;
	}

	public void setPredPartTask(PartTask predPartTask) {
		this.predPartTask = predPartTask;
	}

}
